import javax.print.DocFlavor;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Test4 {


    public static void main(String[] args) {

        int[] nums = {1, 7, 3, 6, 5, 6};
        System.out.println(pivotIndex(nums));
    }

    public int findMaxLength1(int[] nums) {
        HashMap<Integer,Integer> hash = new HashMap<>();
        int sum = 0;
        hash.put(0,-1);
        int len = 0;
        for(int i=0;i<nums.length;i++){
            if (nums[i] == 0){
                sum+=-1;
            }else {
                sum += 1;
            }

            if (hash.containsKey(sum)){
                len = Math.max(len,i-hash.get(sum));
            }
            else {
                hash.put(sum,i);
            }

        }
        return len;


    }

    //连续数组
    public int findMaxLength(int[] nums) {
        HashMap<Integer,Integer> hash = new HashMap<>();
        int sum = 0;
        hash.put(0,-1);
        int len = 0;
        for(int i=0;i<nums.length;i++){
            if (nums[i] == 0){
                sum+=-1;
            }else {
                sum += 1;
            }

            if (hash.containsKey(sum)==false){
                hash.put(sum,i);
            }else {
                len = Math.max(len,i-hash.get(sum));
            }

        }
        return len;


    }




    public int subarraysDivByK(int[] nums, int k) {
        int ret = 0;
        HashMap<Integer,Integer> hash = new HashMap<>();
        hash.put(0%k,1);//哈希表里面存的是余数
        int sum = 0;
        for(int x:nums){
            sum+=x;
            int r = (sum%k+k)%k;
            ret += hash.getOrDefault(r,0);
            hash.put(r,hash.getOrDefault(r,0)+1);

        }

        return ret;

    }


    public int subarraysDivByK1(int[] nums, int k) {
        int n = nums.length;
        int[] dp = new int[n];
        //创建hash表
        HashMap<Integer,Integer> hash = new HashMap<>();

        //初始化前缀和数组
        dp[0] = nums[0];
        for(int i = 1;i<n;i++){
            dp[i] = dp[i-1]+nums[i];
        }



        int ret = 0;
        hash.put(0%k,1);
        for(int i = 0;i<n;i++){

                ret += hash.getOrDefault((((dp[i]-k)%k)+k)%k,0);
                hash.put((((dp[i]-k)%k)+k)%k,hash.getOrDefault((((dp[i]-k)%k)+k)%k,0)+1);


        }

        return ret;


    }





    public int subarraySum(int[] nums, int k) {
        int n = nums.length;
        int[] dp = new int[n];

        //使用哈希表进行存储子数组的个数
        HashMap<Integer,Integer> hash = new HashMap<>();
        //处理前缀和数组
        hash.put(0,1);
        int ret = 0;
        for(int i=0;i<n;i++){
            if (i==0){
                dp[i] = nums[i];
                ret += hash.getOrDefault(dp[i]-k,0);
                hash.put(dp[i],hash.getOrDefault(dp[i],0)+1);
            }else {
                dp[i] = nums[i] + dp[i-1];
                ret += hash.getOrDefault(dp[i]-k,0);
                hash.put(dp[i],hash.getOrDefault(dp[i],0)+1);
            }

        }
        return ret;





    }


    public int subarraySum1(int[] nums, int k) {
        Map<Integer,Integer> hash = new HashMap<>();
        hash.put(0,1);

        int sum = 0,ret = 0;
        for(int x:nums){
            sum+=x;//计算当前位置的前缀和
            ret+=hash.getOrDefault(sum-k,0);//统计结果
            hash.put(sum,hash.getOrDefault(sum,0)+1);//把当前这个前缀和放到hash表
        }
        return ret;

    }


    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] dp1 = new int[n];
        int[] dp2 = new int[n];

        //前缀积数组
        dp1[0] = 1;
        for(int i = 1;i<n;i++){
            dp1[i] = dp1[i-1]*nums[i-1];
        }
        //后缀积数组
        dp2[n-1] = 1;
        for(int i=n-2;i>=0;i--){
            dp2[i] = dp2[i+1]*nums[i+1];
        }

        int[] answer = new int[n];
        for (int i = 0;i<n;i++){
            answer[i] = dp1[i]*dp2[i];
        }
        return answer;

    }


    public static int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] dp1 = new int[n];
        int[] dp2 = new int[n];

        //生成前缀和数组
        dp1[0] = 0;
        for(int i = 1;i<n;i++){
            dp1[i] = dp1[i-1] + nums[i-1];
        }
        //生成后缀和数组
        dp2[n-1] = 0;
        for(int i = n-2;i>=0;i--){
            dp2[i] = dp2[i+1] + nums[i+1];
        }

        //循环遍历
        for(int i = 0;i<n;i++){
            if (dp1[i] == dp2[i]){
                return i;
            }
        }
        return -1;

    }



    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        //输入m n q
        int m = in.nextInt();
        int n = in.nextInt();
        int q = in.nextInt();

        //输入 m*n 的矩阵
        long[][] arr = new long[m+1][n+1];
        for (int i = 1;i<=m;i++){
            for(int j = 1;j<=n;j++){
                arr[i][j] = in.nextInt();
            }
        }

        //创建dp 前缀和矩阵
        long[][] dp = new long[m+1][n+1];
        for(int i = 1;i<=m;i++){
            for(int j = 1;j<=n;j++){
                dp[i][j] = arr[i][j] + dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
            }
        }

        //计算q次之和
        while (q>0){
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            long sum = dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1];
            System.out.println(sum);
            q--;
        }



    }


    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);

        //读入数据
        int n = in.nextInt(),q = in.nextInt();
        int[] arr = new int[n+1];
        for (int i = 1;i<=n;i++){
            arr[i] = in.nextInt();
        }

        //2.预处理前缀和数组
        long[] dp = new long[n+1];
        for(int i = 0;i<=n;i++){
            dp[i] = dp[i-1] + arr[i];
        }
        //使用前缀和数组
        while (q>0){
            int l = in.nextInt(),r = in.nextInt();
            System.out.println(dp[r] - dp[l-1]);
            q--;
        }

    }
}
